<template>
    <a-row :gutter="24">
      <a-col :sm="24" :md="24" :xl="24">
        <h1>今日数据</h1>
        <br/>
      </a-col>
      
      <a-col :sm="24" :md="8" :xl="8" :style="{ marginBottom: '24px' }">
        <my-card :loading="loading" title="新增用户数" :total="userIncreToday">
          
        </my-card>
      </a-col>
      <a-col :sm="24" :md="8" :xl="8" :style="{ marginBottom: '24px' }">
        <my-card :loading="loading" title="总订单数" :total="orderTotal">
          
        </my-card>
      </a-col>
      <a-col :sm="24" :md="8" :xl="8" :style="{ marginBottom: '24px' }">
        <my-card :loading="loading" title="总交易额" :total="amountTotal">
          
        </my-card>
      </a-col>
      <a-row :gutter="24">
        <a-col :sm="6" :md="6" :xl="6">
        </a-col>
         <a-col :sm="6" :md="6" :xl="6" style="text-align:center;">
           <a-button type="dashed" @click="toOrder" value="large">查看详细账单</a-button>
         </a-col>
         <a-col :sm="6" :md="6" :xl="6" style="text-align:center;">
           <a-button type="dashed" @click="toSale" value="large">查看销售数据</a-button>
         </a-col>
         <a-col :sm="6" :md="6" :xl="6">
         </a-col>
      </a-row>
    </a-row>
    

</template>

<script>
  import MyCard from '@/components/MyCard'
  import { getIndexData } from '@/api/api'

  export default {
    name: "PlatIndex",
    components: {
      MyCard,
    },
    data() {
      return {
        loading: true,
        userIncreToday: 0,
        orderTotal: 0,
        amountTotal: '￥0'
      }
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
      }, 1000)
      this.initIndexData();
    },
    methods: {
      initIndexData() {
        getIndexData().then(res => {
          if (res.success) {
            if(res.result) {
              this.orderTotal = res.result.orderTotal;
              this.amountTotal = '￥' + res.result.amountTotal;
            } else {
              this.orderTotal = 0;
              this.amountTotal = '￥0';
            }
          }
        })
      },
      toOrder() {
        this.$router.push({path: '/ilwworder/OrderList'})
      },
      toSale() {
        this.$router.push({path: '/ilwwsale/sale/SaleDataList'})
      }
    }
  }
</script>

<style lang="scss" scoped>
  
</style>